/**   
 * @Title: HeMaiDetailcommunicater.java 
 * @Package com.esun.rabbit2.communicaters.hemai 
 * @Description: TODO(用一句话描述该文件做什么) 
 * @author: Billy Qigs@500wan.com   
 * @date: 2011-12-6 下午5:58:14  
 * Copyright: (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.communicaters.hemai;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.client.ClientProtocolException;
import org.xml.sax.SAXException;

import com.esun.config.BussinessCode;
import com.esun.config.Key;
import com.esun.model.ShengFuRenJiuDetailInfo;
import com.esun.model.ShengfuRenjiuTouzhuInfo;
import com.esun.model.UserInfo;
import com.esun.network.ServerCommunicater;

/**
 * @ClassName: HeMaiDetailcommunicater
 * @Description: (合买方案详情通讯接口)
 * @author: Billy Qigs@500wan.com
 * @date: 2011-12-6 下午5:58:14
 * 
 */
public class HeMaiDetailcommunicater extends ServerCommunicater {

	private String serverMsg = "";

	public boolean isGetDetailSucceed(String lotid, String pid) throws ClientProtocolException, IOException, ParserConfigurationException, SAXException {

		boolean isSucceed = false;

		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		list.add(mapItem(BussinessCode.PASER_MID, BussinessCode.MID_GET_HEMAI_DETAIL_SF_RJ));
		list.add(mapItem(BussinessCode.PASER_CK, UserInfo.getUserInfo().getUserSession()));
		list.add(mapItem(Key.KEY_LOTID, lotid));
		list.add(mapItem(Key.KEY_PID, pid));

		// 写入服务器返回信息
		super.getServerResponse(list, true);
		setServerMessage(super.getServerMsg());
		if (super.getState() == 100) {
			isSucceed = true;
		} else {
			isSucceed = false;
		}
		return isSucceed;

	}

	private void setServerMessage(String str) {
		serverMsg = str;
	}

	public String getServerMsg() {
		return serverMsg;
	}

	public void updateInfo(Hashtable<String, String> info, ArrayList<Hashtable<String, String>> touZhuInfo) {
		ShengFuRenJiuDetailInfo.getInfo().cleanAll();

		ShengFuRenJiuDetailInfo.getInfo().setAddTime(info.get(Key.KEY_ADDTIME));
		ShengFuRenJiuDetailInfo.getInfo().setAllMoney(info.get(Key.KEY_ALLMONEY));
		ShengFuRenJiuDetailInfo.getInfo().setAllNumber(info.get(Key.KEY_ANUMBER));
		ShengFuRenJiuDetailInfo.getInfo().setBaoDiMoney(info.get(Key.KEY_BAODIMONEY));
		ShengFuRenJiuDetailInfo.getInfo().setBeiShu(info.get(Key.KEY_BEISHU));
		ShengFuRenJiuDetailInfo.getInfo().setIsManYuan(info.get(Key.KEY_ISMANYUAN));
		ShengFuRenJiuDetailInfo.getInfo().setIssuc(info.get(Key.KEY_ISSUC));
		ShengFuRenJiuDetailInfo.getInfo().setLeftNumber(info.get(Key.KEY_LEFTNUMBER));
		ShengFuRenJiuDetailInfo.getInfo().setLotteryCount(info.get(Key.KEY_LOTTERYCOUNT));
		ShengFuRenJiuDetailInfo.getInfo().setLotteryMoeny(info.get(Key.KEY_LOTTERYMONERY));
		ShengFuRenJiuDetailInfo.getInfo().setOneMoney(info.get(Key.KEY_ONEMONEY));
		ShengFuRenJiuDetailInfo.getInfo().setTiCheng(info.get(Key.KEY_TICHENG));
		ShengFuRenJiuDetailInfo.getInfo().setUserName(info.get(Key.KEY_USERNAME));
		ShengFuRenJiuDetailInfo.getInfo().setJinDu(info.get(Key.KEY_RENQI));
		ShengFuRenJiuDetailInfo.getInfo().setExpect(info.get(Key.KEY_EXPECT));
		ShengFuRenJiuDetailInfo.getInfo().setIsUpload(info.get(Key.KEY_ISUPLOAD));
		ShengFuRenJiuDetailInfo.getInfo().setIsShow(info.get(Key.KEY_ISSHOW));
		ShengFuRenJiuDetailInfo.getInfo().setPlayID(info.get(Key.KEY_PLAYID));
		ShengFuRenJiuDetailInfo.getInfo().setIsTXT(info.get(Key.KEY_ISTXT));
		// 忘了干嘛的了
		// ShengFuRenJiuDetailInfo.getInfo().setOpencode(info.get(Key.KEY_ISDM));
		ShengFuRenJiuDetailInfo.getInfo().setFilecode(info.get(Key.KEY_FILEORCODE));

		ArrayList<ShengfuRenjiuTouzhuInfo> list = new ArrayList<ShengfuRenjiuTouzhuInfo>();

		for (int i = 0; i < touZhuInfo.size(); i++) {
			ShengfuRenjiuTouzhuInfo item = new ShengfuRenjiuTouzhuInfo();

			item.setHomeTeam(touZhuInfo.get(i).get(Key.KEY_HOMETEAM));
			item.setVisitingTeam(touZhuInfo.get(i).get(Key.KEY_GUESTTEAM));
			item.setDanMa(touZhuInfo.get(i).get(Key.KEY_ISDM));
			item.setTouZhu(touZhuInfo.get(i).get(Key.KEY_SHUTIN));
			// item.setScore(touZhuInfo.get(i).get(""));

			list.add(item);
		}

		ShengFuRenJiuDetailInfo.getInfo().setTouZhuInfo(list);
		ShengFuRenJiuDetailInfo.getInfo().setIsChaser(info.get(Key.KEY_ISCHASER));

	}

	private HashMap<String, String> mapItem(String name, String value) {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put(name, value);
		return map;
	}

}
